<?php
/*
 * General Functions
 * 
 * Mainly used functions
 * 
 * @author : Jason Meulenhoff
 * @mail : mail@kacangboi.com
 * @web : http://kacangboi.com
 * @copyright : KacangNetworks 2010
 * 
 */

function readVideoDirectory()
{
	$database = new databaseManager();
	
	if($handle = opendir("../../streams/"))
	{
		while (false !== ($file = readdir($handle))) 
		{
			$parts = explode("_",$file);
			if(strlen($file) > 2 && substr($parts[0],0,4) == PORTAL_NAME)
			{
				if(time() <= (strtotime($parts[1]) + VIDEO_AVAILABLE))
				{
					$dateParts = explode("-",$parts[1]);
					(string) $date = $dateParts[0] . $dateParts[1];
					
					if(!$database->videoExists($file))
						$database->insertNewVideos($file,strtolower($parts[0]),PORTAL_NAME,$date,substr($parts[3],0,2));
				}
				else
					$database->deleteVideo($file);
			}
		}	
	    closedir($handle);
	}
}
?>